// pages/sales/moneydetail/moneydetail.js
const app = getApp();
import { disOrder } from '../../../../config/https.js';
import { u_formatTimestamp } from '../../../../config/tool.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    page: 0,
    pagesize: 5,
    noMore: false,
    isNone: false,
    //为空提示
    emptyTip: {
      font: "暂时还没有订单哦~",
      imgUrl: "../../../../assets/img/sormx_empty.png"
    },
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData();
  },

  // 获取数据
  getData(){
    app.loading();
    disOrder({
      token: wx.getStorageSync('userId'),
      page: ++this.data.page,
      pagesize: this.data.pagesize
    }).then(res =>{
      wx.hideLoading();
      if(res.code == 1){
        if(res.data.list.length > 0){
          res.data.list.forEach((item)=>{
            item.create_time = u_formatTimestamp(item.create_time * 1000)
          })
          this.setData({
            list: [...this.data.list, ...res.data.list],
            noMore: Number(res.data.list.length) < Number(this.data.pagesize) ? true : false
          })
        }else{
          this.setData({
            noMore: true
          })
        }
        if(this.data.list.length > 0){
          this.setData({
            isNone: false
          })
        }else{
          this.setData({
            isNone: true
          })
        }
      }else{
        app.$tip(res.msg)
      }
    })

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(!this.data.noMore){
      this.getData()
    }
  },
})